﻿using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling;
using Microsoft.Practices.EnterpriseLibrary.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;



namespace Janus.Cores
{
    public static class Loger
    {
        public static ExceptionManager em = EnterpriseLibraryContainer.Current.GetInstance<ExceptionManager>();

        public static void Process(Action action)
        {
            em.Process(action, "Policy");
        }
        //private static readonly Logger logger = LogManager.GetCurrentClassLogger();
        public static void WriteLog(string msg)
        {
            var log = new LogEntry();
            log.Message = msg;
            WriteLog(log);
        }
        public static void WriteLog(LogEntry log)
        {
            Logger.Writer.Write(log);
            //ServiceFactory.LogWriter.Write(log);
        }


        public static void WriteLog(Exception ex)
        {
            try
            {
                if (ex.InnerException != null)
                {
                    ex = ex.InnerException;
                }
                em.Process(() => {  throw ex; }, "Policy");
            }
            catch (Exception e)
            {
#if DEBUG
                //throw e;
#endif
            }
        }
    }
}
